package com.filter;

import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.convert.Converter;
import javax.faces.convert.FacesConverter;

import com.dao.SingularDAO;
import com.model.Singular;

@FacesConverter(value = "singularConverter")
public class SingularConverter implements Converter {
	
	private SingularDAO singularDAO = new SingularDAO();
	private Singular singular;

	@Override
    public Object getAsObject(FacesContext arg0, UIComponent arg1, String arg2) {
        if (arg2 != null && !arg2.equals("null")) {
        	singularDAO.beginTransaction();
			singular = singularDAO.findSingularByNome(arg2);
            return singular;
        } else {     
        	return null;
        }
    }
    @Override
    public String getAsString(FacesContext arg0, UIComponent arg1, Object arg2) {
        return String.valueOf(arg2);
    }
}